home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
ada
/
gwuada_9.zip
/
SMISC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-20
|
43KB
|
1,423 lines
/*
* Copyright (C) 1985-1992 New York University
*
* This file is part of the Ada/Ed-C system. See the Ada/Ed README file for
* warranty (none) and distribution info and also the GNU General Public
* License for more details.
*/
#include "hdr.h"
#include "vars.h"
#include "setp.h"
#include "dbxp.h"
#include "arithp.h"
#include "chapp.h"
#include "dclmapp.h"
#include "miscp.h"
#include "smiscp.h"
/* smisc.c: miscellaneous sem procedures needing semhdr.h */
/*
* 23-sep-85 ds
* add ast_clear to clear defined ast fields before resetting N_KIND.
*
* 11-jul-86 ACD
* modified the DEFINED fields for length clauses. Previously only
* N_AST1 was recognized as being defined. Now, both N_AST1 (the
* attribute node) and N_AST2 ( the expression) are recognized
*
* 16-apr-85 ds
* add procedures fordeclared_1 and fordeclared_2. These are used to
* initialize and advance iteration over declared maps, and are
* introduced to reduce the size of the FORDECLARED macro.
*
* 24-dec-84 ds
* have dcl_put NOT set visibility by default.
*
* 07-nov-84 ds
* have node_new_noseq set spans info.
* add spans_copy(new, old) to copy spans information from node old
* to node new.
*
* 04-nov-84 ds
* move undone() here as undone.c no longer needed.
*
* 02-nov-84 ds
* add attribute_str to return attribute name based on attribute
* code in N_VAL field of attribute node.
*
* 22-oct-84 ds
* add dcl_put_vis to enter with explicit visibility indication.
*
* 12-oct-84 ds
* merge in procedures formerly in dcl.c
*/
static int const_cmp_kind(Const, Const);
void ast_clear(Node node) /*;ast_clear*/
{
int nk = N_KIND(node);
if (N_AST2_DEFINED(nk)) N_AST2(node) = (Node) 0;
if (N_AST3_DEFINED(nk)) N_AST3(node) = (Node) 0;
if (N_AST4_DEFINED(nk)) N_AST4(node) = (Node) 0;
}
Const const_new(int k) /*;const_new*/
{
Const result;
result = (Const) smalloc(sizeof(Const_s));
result->const_kind = k;
result->const_value.const_int = 0; /* reasonable default value */
return result;
}
Const int_const(int x) /*;int_const*/
{
Const result;
result = const_new(CONST_INT);
result->const_value.const_int = x;
return result;
}
Const fixed_const(long x) /*;fixed_const*/
{
Const result;
result = const_new(CONST_FIXED);
result->const_value.const_fixed = x;
return result;
}
Const uint_const(int *x) /*;uint_const*/
{
Const result;
if (x == (int *)0) result = const_new(CONST_OM);
else {
result = const_new(CONST_UINT);
result->const_value.const_uint = x;
}
return result;
}
Const real_const(double x) /*;real_const*/
{
Const result;
result = const_new(CONST_REAL);
result->const_value.const_real = x;
return result;
}
Const rat_const(Rational x) /*;rat_const*/
{
Const result;
if (x == (Rational)0) result = const_new(CONST_OM);
else {
result = const_new(CONST_RAT);
result->const_value.const_rat = x;
}
return result;
}
/* Comparison functions for ivalues (Const's) */
int const_eq(Const const1, Const const2) /*;const_eq*/
{
/* checks to see if 2 Consts have the same value */
switch (const_cmp_kind(const1, const2)) {
case CONST_OM:
case CONST_CONSTRAINT_ERROR:
return TRUE;
case CONST_INT:
return (INTV(const1) == INTV(const2));
case CONST_FIXED:
return (FIXEDV(const1) == FIXEDV(const2));
case CONST_UINT:
return int_eql(UINTV(const1), UINTV(const2));
case CONST_REAL:
return (RATV(const1) == RATV(const2));
case CONST_RAT:
return rat_eql(RATV(const1), RATV(const2));
case CONST_STR:
return streq(const1->const_value.const_str,
const2->const_value.const_str);
default:
return const_cmp_undef(const1, const2);
}
}
int const_ne(Const cleft, Const cright) /*;const_ne*/
{
return !const_eq(cleft, cright);
}
int const_lt(Const cleft, Const cright) /*;const_lt*/
{
switch (const_cmp_kind(cleft, cright)) {
case CONST_INT :
return (INTV(cleft)<INTV(cright));
case CONST_UINT :
return int_lss(UINTV(cleft), UINTV(cright));
case CONST_FIXED :
return (FIXEDV(cleft)<FIXEDV(cright));
case CONST_RAT :
return rat_lss(RATV(cleft), RATV(cright));
case CONST_REAL :
return REALV(cleft) < REALV(cright);
default :
const_cmp_undef(cleft, cright);
return 0;
}
}
int const_le(Const cleft, Const cright) /*;const_le*/
{
return (const_eq(cleft, cright) || const_lt(cleft, cright));
}
int const_gt(Const cleft, Const cright) /*;const_gt*/
{
return const_lt(cright, cleft);
}
int const_ge(Const cleft, Const cright) /*;const_ge*/
{
return const_eq(cleft, cright) || const_lt(cright, cleft);
}
static int const_cmp_kind(Const cleft, Const cright) /*;const_cmp_kind*/
{
int ckind;
ckind = cleft->const_kind;
if (ckind == CONST_OM) chaos("const comparison left operand not defined");
if (ckind != cright->const_kind) {
#ifdef DEBUG
zpcon(cleft);
zpcon(cright);
#endif
chaos("const comparison operands differing kinds");
}
return ckind;
}
int const_same_kind(Const cleft, Const cright) /*;const_same_kind*/
{
/* returns boolean value indicating whether two Consts are of same kind */
return (cleft->const_kind == cright->const_kind);
}
int const_cmp_undef(Const cleft, Const cright) /*;const_cmp_undef*/
{
#ifdef DEBUG
zpcon(cleft);
zpcon(cright);
#endif
chaos("const comparison not defined for these constant types");
return 0; /* for sake of lint */
}
int fx_mantissa(Rational lbd, Rational ubd, Rational small) /*;mantissa*/
{
Rational exact_val;
int *vnum, *vden, *int_1;
int power;
lbd = rat_abs(lbd);
ubd = rat_abs(ubd);
/* find the exact # of values to be represented (aside from 0) */
if (rat_gtr(lbd, ubd))
exact_val = rat_div(lbd, small);
else
exact_val = rat_div(ubd, small);
vnum = num(exact_val);
vden = den(exact_val);
int_1 = int_fri(1);
/* the mantissa is calculated assuming that the bound is 'small away
* from a model number, so we subtract one before computing no. of bits
*/
vnum = int_sub(vnum, int_1);
vnum = int_quo(vnum, vden);
vden = int_fri(1);
power = 1;
while (int_gtr(vnum, vden)) {
power++;
vden = int_add(int_add(vden, vden), int_1);
}
return power;
}
/* Not used */
void node_free(Node node) /*;node_free*/
{
/* free nodeentry. Since state of allocated fields not clear
* only free the node block itself
*/
chaos("node free");
if (node != (Node)0) efreet((char *) node, "node-free");
}
void to_errfile(char *txt) /*;to_errfile */
{
printf("%s\n", txt);
}
int needs_body(Symbol name) /*;needs_body*/
{
/* Procedures and function specs need bodies of course. So do package
* specs that contain objects which need bodies.
*/
Symbol obj;
char *id;
Fordeclared fd1;
int nat;
if (cdebug2 > 3) TO_ERRFILE("AT PROC : needs_body");
nat = NATURE(name);
if (nat == na_package_spec || nat == na_generic_package_spec) {
FORDECLARED(id, obj, DECLARED(name), fd1);
if (IS_VISIBLE(fd1) && obj->scope_of == name
&& needs_body(obj)) return TRUE;
ENDFORDECLARED(fd1);
FORDECLARED(id, obj, DECLARED(name), fd1)
if (TYPE_OF(obj) == symbol_incomplete) return TRUE;
ENDFORDECLARED(fd1);
return FALSE;
}
if (nat == na_procedure_spec || nat == na_function_spec
|| nat == na_task_type_spec || nat == na_task_obj_spec
|| nat == na_generic_procedure_spec || nat == na_generic_function_spec)
return TRUE;
return FALSE;
}
/* The text of kind_str that follows is generated by a spitbol program
* called AS
*/
char *kind_str(unsigned int as) /*;kind_str*/
{
static char *as_names[] = {
"pragma",
"arg",
"obj_decl",
"const_decl",
"num_decl",
"type_decl",
"subtype_decl",
"subtype_indic",
"derived_type",
"range",
"range_attribute",
"constraint",
"enum",
"int_type",
"float_type",
"fixed_type",
"digits",
"delta",
"array_type",
"box",
"subtype",
"record",